//
//  AdjustPriceVC.m
//  NtoccShipper
//
//  Created by mac on 2019/12/12.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "AdjustPriceVC.h"

@interface AdjustPriceVC ()
@property (nonatomic,strong) CJTextField *fieldWeight;
@property (nonatomic,strong) CJTextField *fieldCarNums;
@property (nonatomic,strong) CJTextField *fieldPrice;
@property (nonatomic,strong) CJTextField *fieldAdjustPrice;


@end

@implementation AdjustPriceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.\
    
    [self setTitleName:@"调价"];
    [self setBackLeftButton:@""];
    [self createTopView];
    [self setFieldLimit];
}

- (void)createTopView{
    
    //    WS(ws);
    CGRect rcFrame = CGRectMake(0, kTopHeight, [[UIScreen mainScreen] bounds].size.width, 0);
    FlexFrameView *header = [[FlexFrameView alloc] initWithFlex:@"AdjustPriceTopView" Frame:rcFrame Owner:self];
    header.flexibleHeight = YES;
    self.fieldPrice.text = @(self.model.price).cj_money_description;
    self.fieldWeight.text = @(self.model.lastWeight).cj_description;
    self.fieldCarNums.text = CJStringWithFormat(@"%ld",(long)self.model.notReceivedCount);

    [header layoutIfNeeded];
    [self.view addSubview:header];

}
- (void)setFieldLimit{
    
    self.fieldAdjustPrice.textFieldType = CJTextFieldStringTypeMoneyValue;
    self.fieldAdjustPrice.maxLength = CJTextLengthTen;
}
- (void)btnSaveAction{

    if ([CJRegular getIsStrEmpty:self.fieldAdjustPrice.text]) {
        [CJAlert showStringDismissWithDelay:@"输入调价单价"];
    }else if (![CJRegular getIsMonayValue:self.fieldAdjustPrice.text]){
        [CJAlert showStringDismissWithDelay:@"输入正确的调价金额"];

    }
    else{
         NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/order/updateOrderPrice",CJBaseUrl);
         NSDictionary *dicPar = @{@"code":self.strCode,
                                  @"price":self.fieldAdjustPrice.text
         };
         
         WS(ws);
         [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
             
             DLog(@"++++++++%@",responseObject);
             
             if (ws.blockSuccess) {
                 ws.blockSuccess(@"");
                 [ws pop];
             }
             
         } failure:^(NSError * _Nonnull error) {
             DLog(@"++++++++%@",error);
             
         }];

    }
 
}

@end
